﻿using System;
using System.Configuration;

namespace Sirocco.Core
{
    public class DirectoryConfigurationCollection : ConfigurationElementCollection
    {

        public DirectoryConfigurationCollection()
        {
            var directoryElement = (DirectoryConfigurationElement)CreateNewElement();
            Add(directoryElement);
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new DirectoryConfigurationElement();
        }


        protected override ConfigurationElement CreateNewElement(string elementName)
        {
            return new DirectoryConfigurationElement(elementName);
        }


        protected override Object GetElementKey(ConfigurationElement element)
        {
            return ((DirectoryConfigurationElement)element).Name;
        }


        public new string AddElementName
        {
            get { return base.AddElementName; }
            set { base.AddElementName = value; }
        }

        public new string ClearElementName
        {
            get { return base.ClearElementName; }
            set { base.AddElementName = value; }
        }

        public new string RemoveElementName
        {
            get { return base.RemoveElementName; }
        }

        public new int Count
        {
            get { return base.Count; }
        }

        public DirectoryConfigurationElement this[int index]
        {
            get { return (DirectoryConfigurationElement)BaseGet(index); }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        new public DirectoryConfigurationElement this[string Name]
        {
            get { return (DirectoryConfigurationElement)BaseGet(Name); }
        }

        public int IndexOf(DirectoryConfigurationElement directoryElement)
        {
            return BaseIndexOf(directoryElement);
        }

        public void Add(DirectoryConfigurationElement directory)
        {
            BaseAdd(directory);
            // Add custom code here.
        }

        protected override void BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
            // Add custom code here.
        }

        public void Remove(DirectoryConfigurationElement directory)
        {
            if (BaseIndexOf(directory) >= 0)
                BaseRemove(directory.Name);
        }

        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        public void Remove(string name)
        {
            BaseRemove(name);
        }

        public void Clear()
        {
            BaseClear();
            // Add custom code here.
        }
    }
}
